package com.heima.user.controller.v1;

import com.heima.common.constants.user.UserConstants;
import com.heima.common.exception.LeadNewsException;
import com.heima.model.common.dto.ResponseResult;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.user.dto.AuthDto;
import com.heima.model.user.pojo.ApUserRealName;
import com.heima.user.service.ApUserRealNameService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import sun.rmi.runtime.Log;

import javax.ws.rs.POST;
import java.util.Objects;

/**
 * @author Ronaldo
 * @date 2021/8/1
 */
@RestController
@RequestMapping("/api/v1/auth")
@Slf4j
public class ApUserRealNameController {

    @Autowired
    private ApUserRealNameService apUserRealNameService;

    @PostMapping("/list")
    public ResponseResult queryPage(@RequestBody AuthDto authDto){

        log.info("query auth info in pages according to {}" + authDto);

        //参数判断
        if (Objects.isNull(authDto)){
            throw new LeadNewsException(AppHttpCodeEnum.PARAM_INVALID);
        }
        return apUserRealNameService.queryPage(authDto);
    }

    /**
     * 审核通过
     * @param authDto
     * @return
     */
    @PostMapping("/authPass")
    public ResponseResult authPass(@RequestBody AuthDto authDto){

        log.info("approve {}" + authDto);

        if (Objects.isNull(authDto)){
            throw new LeadNewsException(AppHttpCodeEnum.PARAM_INVALID);
        }
        return apUserRealNameService.examine(authDto, UserConstants.PASS_AUTH);
    }


    /**
     * 审核驳回
     * @param authDto
     * @return
     */
    @PostMapping("/authFail")
    public ResponseResult authFail(@RequestBody AuthDto authDto){

        log.info("not approve {}" + authDto);

        if (Objects.isNull(authDto)){
            throw new LeadNewsException(AppHttpCodeEnum.PARAM_INVALID);
        }
        return apUserRealNameService.examine(authDto,UserConstants.FAIL_AUTH);
    }
}
